<template>
  <view >

    <uni-data-picker placeholder="请选择指标所属城市" popup-title="请选择指标所属城市" :localdata="dataTree" v-model="citySelection"
                     @change="onchange">
    </uni-data-picker>

  </view>
</template>

<script>
import {treeByArea} from '@/api/system/dept.js'
export default {
  name: 'isLimitCity',//指标所属城市
  props: {
    value: {
      type: [Array, String],
      default() {
        return []
      }
    },
  },
  computed: {},
  watch: {
    value: {
      handler(val) {
        // console.log('val', val)
        this.citySelection = val && val.length ? val.split(",") : []
      },
      deep: true,
      immediate:true
    },
  },
  data() {
    return {
      dataTree:[],
      citySelection:[]
    };
  },
  created() {
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData(){
      treeByArea({
        regionLevel:2,//显示级别 1省 2省市 3省市区 ；为空默认3
        areaId:null //区域id；为空默认全国
      }).then(res=>{
        res.data = res.data.map(item=>{
          item.text = item.label;
          item.children = item.children.map(citem=>{
            citem.text = citem.label;
            citem.children = citem.children.map(ditem=>{
              ditem.text = ditem.label;
              ditem.children = null
              return ditem
            })
            return citem
          })
          return item
        })
        this.dataTree = res.data
      })
    },
    onchange(e){
      if(e && e.detail.value && e.detail.value.length>0){
        this.$emit("change", e.detail.value)
      }else {
        this.$emit("change", null)
      }
    }
  },
};
</script>

<style scoped lang=""></style>


